package SOEN_Phase_2;

import junit.framework.TestCase;
import junit.framework.Test;
import junit.framework.Assert;
import java.io.File;

public class TaskTableTest extends TestCase{

	
	public void setUp() throws Exception {
	}

	public void testInitializeFromFile() {
		
		TaskTable tskT = new TaskTable("tasks.xml");
		Assert.assertNotSame(tskT, null);
	}

	
	public void testWriteToTXT() {

		TaskTable tskTable = new TaskTable("tasks.xml");
		tskTable.writeToTXT("./", "Tasks.txt");
		File f = new File("Tasks.txt");
		
		Assert.assertTrue(f.exists());
	}

	
	public void testModifyTaskTitle() {
		String newTitle = "";
		
		TaskTable tskT = new TaskTable( "tasks.xml ");
		Task task = (Task)tskT.getTasks()[0];
		String titleBeforeMod = task.getTitle();
		
		tskT.modifyTaskTitle(task.getID(), "New Title is new");
		
		newTitle = task.getTitle();
		Assert.assertNotSame(titleBeforeMod, newTitle);
	}

	
	public void testModifyEstimatedDuration() {
		int  newDuartion = 4 ;
		
		TaskTable tskT = new TaskTable( "tasks.xml ");
		Task task = (Task)tskT.getTasks()[0];
		int durationBeforeMod = task.getDuration();
		
		tskT.modifyEstimatedDuration(task.getID(), 44);
		
		newDuartion = task.getDuration();
		Assert.assertNotSame(durationBeforeMod, newDuartion);
	}

	
	public void testModifyAssignee() {
		String  newAssigneeID = "4" ;
		TaskTable tskT = new TaskTable( "tasks.xml ");
		Task task = (Task)tskT.getTasks()[0];
		
		int AssigneeIDBeforeMod = task.getAssigneeID();
		tskT.modifyAssignee(task.getID(), newAssigneeID);
		
		Assert.assertNotSame(AssigneeIDBeforeMod, newAssigneeID);
	}
	
	
	

	
	public void testModifyCompletion() 
	{	
		int  newDuration = 4 ;
		
		TaskTable tskT = new TaskTable( "tasks.xml ");
		Task task = (Task)tskT.getTasks()[0];
		int durationBeforeMod = task.getDuration();
		
		tskT.modifyEstimatedDuration(task.getID(), newDuration);

		Assert.assertNotSame(durationBeforeMod, newDuration);
	}

	
	public void testModifyTimeInvested() {

		int  newTimeAdded = 4 ;
		
		TaskTable tskT = new TaskTable( "tasks.xml ");
		Task task = (Task)tskT.getTasks()[0];
		int TimeBeforeMod = task.getTimeInvested();
		
		tskT.modifyTimeInvested(task.getID(), newTimeAdded);
		int TimeAfterMod = task.getTimeInvested();

		Assert.assertEquals(TimeAfterMod, TimeBeforeMod+newTimeAdded);
		
		
	}

	
	public void testSaveToXML() {
		TaskTable tskT = new TaskTable("tasks.xml");
		tskT.saveToXML("new_tasks.xml");
		
		File f = new File("new_tasks.xml");
		Assert.assertTrue(f.exists());
	}

	
	public void testDeleteTask() {
		TaskTable tskT = new TaskTable("tasks.xml");
		Task tsk = (Task)tskT.getTasks()[0];
		
		Task deleted = tskT.deleteTask(tsk.getID());
		
		Assert.assertNotNull(deleted);
	}

}

